package com.conlin.learn.io;

import com.conlin.learn.common.contant.Contant;
import com.conlin.learn.common.proxy.CommonService;

import java.io.*;

public class BufferedStreamCopyDecorator implements CommonService {
    @Override
    public void doSomething() {
        String path = "K:\\jdk-8u171-windows-x64.exe";
        String outPath = "J:\\java_work\\files\\jdk-8u171-windows-x64.exe";

        try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(path));
             BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(outPath))) {

            byte[] bytes = new byte[Contant.BYTE_LENGTH];
            int c;
            while ((c = bufferedInputStream.read(bytes)) != -1) {
                bufferedOutputStream.write(bytes, 0, c);
            }

            bufferedOutputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
